{include file='header'/}
<body class="pear-admin">
<form class="layui-form" action="{:url('auth_group/add')}" method="post">
    <div class="mainBox">
        <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label">角色名称</label>
                <div class="layui-input-block">
                    <input type="text" name="name" id="name" lay-verify="required" autocomplete="off"
                           placeholder="请输入角色名称"
                           class="layui-input" value="">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">选择权限</label>
                <div class="layui-input-block">
                    <div id="node_ids" class="demo-tree-more"></div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <input type="radio" name="status" value="1"
                           title="启用" checked>
                    <input type="radio" name="status" value="0"
                           title="禁用">
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <input type="hidden" name="__token__" value="{:token()}" />
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="admin-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>

{include file='footer'/}
<script>
  layui.use(['form', 'jquery'], function () {
    let form = layui.form;
    let $ = layui.jquery;
    let tree = layui.tree;
    load_tree(1);

    function load_tree(id = 1) {
      $.ajax({
        url: "{:url('auth_group/authorize')}?id=" + id,
        dataType: 'json',
        success: function (res) {
          res.data = res.data || [];
          tree.render({
            elem: '#node_ids',
            data: res.data,
            showCheckbox: true,
            id: 'nodeDataId',
          });
        }
      });
    }
  })
</script>
